from daos import get_db_session, get_update_contents
from models.album_broadcast_record_info import AlbumBroadcastRecordInfo


def add_album_broadcast_record_info(model_orm: AlbumBroadcastRecordInfo, is_commit=True):
    session = get_db_session()

    session.add(model_orm)
    session.commit() if is_commit else session.flush()
    return model_orm


def query_album_broadcast_record_info(pk):
    return get_db_session().query(AlbumBroadcastRecordInfo).filter(AlbumBroadcastRecordInfo.id == pk).first()


def query_album_broadcast_record_info_by_album_info_id(album_info_id):
    return get_db_session().query(AlbumBroadcastRecordInfo).filter(
        AlbumBroadcastRecordInfo.album_info_id == album_info_id).first()


def update_album_broadcast_record_info(model_orm: AlbumBroadcastRecordInfo, *args, is_commit=True):
    session = get_db_session()
    update_contents = get_update_contents(model_orm, *args)
    session.query(AlbumBroadcastRecordInfo).filter(AlbumBroadcastRecordInfo.album_info_id == model_orm.album_info_id).update(update_contents)
    session.commit() if is_commit else session.flush()
    return
